function paginate(page,id, pNum) {

	if(page.pageCounts<2) return;

	// var url = addUrlPara(url, "pageSize", pageSize);

	var html = "<ul class=\"pagination\">";

	if (pNum == undefined) {
		pNum = 10;
	}

	var numSize = pNum;
	var haf = parseInt(numSize / 2);

	if (page.pageIndex > page.pageCounts) {
		page.pageIndex = page.pageCounts + 1;
	}

	var preCount = (page.pageIndex - 1) > 0 ? (page.pageIndex - 1) : 0;
	var nextCount = (numSize - preCount - 1) > 0 ? (numSize - preCount - 1) : 1;

	if (preCount > haf) {
		nextCount += preCount - haf;
	}
	preCount = preCount > haf ? haf : preCount;
	nextCount = nextCount > (page.pageCounts - page.pageIndex) ? (page.pageCounts - page.pageIndex) : nextCount;
	nextCount = (nextCount + preCount + 1) > numSize ? numSize - preCount - 1 : nextCount;
	if (nextCount < haf) {
		preCount = numSize - nextCount - 1;
		preCount = preCount > (page.pageIndex - 1) ? (page.pageIndex - 1) : preCount;
	}

	html +="<li class=\"disabled\"><a href=\"#\">共"+page.allRows+"条</a></li>";

    if(page.pageIndex - preCount>1){
        html += "<li><a href=\"#\">首页</a></li>";
    }

	if(page.pageIndex==1){
        html +='<li class="disabled"><a href="#"><i class="fa fa-angle-left"></i></a></li>';
	}else{
        html +='<li><a href="#"><i class="fa fa-angle-left"></i></a></li>';
	}


	//前几页
	for (var i = page.pageIndex - preCount; i < page.pageIndex; i++) {
		// var urlPre = addUrlPara(url, "page.pageIndex", i);
		html += "<li><a href=\"#\">" + i + "</a></li>";
	}

	//当前页
	html += "<li class='active'><a>" + page.pageIndex + "</a></li>";

	//后几页
	for (var i = 1; i <= nextCount; i++) {
		// var urlPre = addUrlPara(url, "page.pageIndex", page.pageIndex + i);
		html += "<li><a href=\"#\">" + ( page.pageIndex + i) + "</a></li>";
	}

	//下一页
	if (page.pageIndex < page.pageCounts) {
		// var urlNext = addUrlPara(url, "page.pageIndex", page.pageIndex + 1);
		html += "<li><a href=\"#\"><i class=\"fa fa-angle-right\"></i></a></li>";
	} else {
		html += "<li class=\"disabled\"><a href=\"#\"><i class=\"fa fa-angle-right\"></i></a></li>";
	}

	//最后一页
	if (page.pageIndex != page.pageCounts && page.pageCounts != 0) {
		// var urlLast = addUrlPara(url, "page.pageIndex", page.pageCounts);
		html += "<li><a href=\"#\">" + page.pageCounts + "</a></li>";
	} else {
		html += "<li class=\"disabled\"><a href=\"#\">" + page.pageCounts + "</a></li>";
	}

	html += "</ul>";
	var widget = $("#" + id);
	widget.html("");
	widget.append(html);
};



function clickBind(page,funName,params) {
    $("#pagination-hsx li a").on("click", function () {
        pageIndex=$(this).html();
        if(pageIndex=='<i class="fa fa-angle-right"></i>'){
            page.pageIndex=page.pageIndex>=page.pageCounts ? page.pageCounts : page.pageIndex+1;
        }else if(pageIndex=='<i class="fa fa-angle-left"></i>'){
            page.pageIndex=page.pageIndex<=1 ? 1 : page.pageIndex-1;
        }else if(pageIndex=="首页"){
            page.pageIndex=1;
        }else{
            page.pageIndex=$(this).html();
        }
        var fun=eval(funName);

		if(params==undefined){
            fun.call(this,page.pageIndex);
		}else{
            fun.call(this,page.pageIndex,params);
		}

    });
}


